package cn.earl.springboot.test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.junit.Test;

public class DateCompare {

	@Test
	public void date() throws InterruptedException {
		SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		 String format = form.format(date);
		 System.out.println(format);
		Calendar c1 = Calendar.getInstance();
		Thread.sleep(5000);
		Calendar c2 = Calendar.getInstance();
		System.out.println(c1);
		System.out.println(c2.getTimeInMillis()-c1.getTimeInMillis());
	}
	
	@Test
	public void printDate() throws ParseException{
		String formatDate = null;  
		Date date = new Date();  
		// 输出格式: 2015-1-27 00:00:00 大写H为24小时制  
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		formatDate = sdf.format(date);  
		System.out.println(formatDate);
		Date dd = sdf.parse(formatDate);
		System.out.println(dd);  
	}
	
	@Test
	public void subDate() throws ParseException{
		String s1= "2017-08-09 12:06:30";
		String s2= "2017-08-10 12:36:30";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date d1 = sdf.parse(s1);
		Date d2 = sdf.parse(s2);
		System.out.println((d2.getTime()-d1.getTime())/60000);
	}
	

}
